package common

import (
	"Project/global"
	"Project/model/common/request"
	"Project/model/common/response"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"log"
)

type ExcelApi struct {}

// RecordExcel 导出excel
func (e *ExcelApi) RecordExcel(c *gin.Context) {
	var excelInfo request.ExcelInfo
	if err := c.ShouldBindJSON(&excelInfo);err != nil {
		log.Println("参数绑定失败")
		global.GVA_LOG.Error("参数绑定失败!", zap.Error(err))
		response.Fail(c)
		return
	}
	filePath := global.GVA_CONFIG.Excel.Dir + excelInfo.FileName+".xlsx"
	err := excelService.RecordExcel(excelInfo.InfoList,filePath)
	if err != nil {
		log.Println("转换excel失败")
		global.GVA_LOG.Error("转换Excel失败!", zap.Error(err))
		response.Fail(c)
		return
	}
	c.Writer.Header().Add("success","true")
	c.File(filePath)
}
